package com.example.photo_application;

import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public  class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>{
    private Context context;
    private  int[] photos;
    public AlbumAdapter(Context context,int[] photos){
        this.context=context;
        this.photos=photos;

    }

    @NonNull

    @Override
    //创建viewHold
    public ViewHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        View itemview= LayoutInflater.from(context).inflate(R.layout.list_item,parent,false);
        return new ViewHolder(itemview);
    }

    @Override
    public void onBindViewHolder(@NonNull AlbumAdapter.ViewHolder holder, int position) {
        holder.iv_img.setImageResource(photos[position]);
    }

    @Override
    public int getItemCount() {
        return photos==null?0:photos.length;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_img;

        public ViewHolder(@NonNull  View itemView) {
            super(itemView);
            iv_img=itemView.findViewById(R.id.iv_img);
        }
    }

}
